home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / graphics / gnuplot / win / geticon.c < prev    next >
C/C++ Source or Header  |  1993-09-15  |  2KB  |  99 lines

  1. #ifndef lint
  2. static char *RCSid = "$Id: geticon.c%v 3.50 1993/07/09 05:35:24 woo Exp $";
  3. #endif
  4.  
  5. /* geticon.c */
  6. /* extract Borland ascii format icons from resource script */
  7. /* and write as Microsoft binary format .ICO files */
  8. /* Russell Lang 1992-12-20 */
  9.  
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #include <ctype.h>
  14.  
  15. #define MAXLINE 255
  16. FILE *rcfile;
  17. char inline[MAXLINE+1];
  18. char *tok1, *tok2, *tok3;
  19. char *p;
  20. char iconname[MAXLINE+1];
  21. FILE *iconfile;
  22. int line;
  23.  
  24. int htoi(char ch)
  25. {
  26.     ch = toupper(ch);
  27.     if (ch < '0')
  28.         return(0);
  29.     else if (ch <= '9')
  30.         return((int)(ch - '0'));
  31.     else if (ch < 'A')
  32.         return(0);
  33.     else if (ch <= 'F')
  34.         return((int)(ch - 'A' + 10));
  35.     return(0);
  36. }
  37.  
  38. void
  39. geticon(void)
  40. {
  41. char ch;
  42.     fgets(inline,MAXLINE,rcfile);
  43.     line++;
  44.     if (strncmp(inline,"BEGIN",5)) {
  45.         fprintf(stderr,"Expecting BEGIN at line %d\n",line);
  46.         exit(3);
  47.     }
  48.     if ( (iconfile = fopen(iconname,"wb")) == (FILE *)NULL) {
  49.         fprintf(stderr,"Can't open ICON file %s\n",iconname);
  50.         exit(4);
  51.     }
  52.     fgets(inline,MAXLINE,rcfile);
  53.     line++;
  54.     while (strncmp(inline,"END",3) && !feof(rcfile)) {
  55.         for (p = inline; *p && (*p==' ' || *p == '\t' || *p=='\''); p++);
  56.         while (isxdigit(*p)) {
  57.             ch = htoi(*p++)<<4;
  58.             ch += htoi(*p++);
  59.             fputc(ch, iconfile);
  60.             p++;
  61.         }
  62.         fgets(inline,MAXLINE,rcfile);
  63.         line++;
  64.     }
  65.     fclose(iconfile);
  66. }
  67.  
  68. int
  69. main(int argc, char *argv[])
  70. {
  71.     if ((argc < 2) || (argc > 3)) {
  72.     fprintf(stderr,"Usage:  geticon  resource_file [icon_directory]\n");
  73.     return(1);
  74.     }
  75.     if ( (rcfile = fopen(argv[1],"r")) == (FILE *)NULL) {
  76.     fprintf(stderr,"Can't open RC file\n");
  77.     return(2);
  78.     }
  79.     line = 0;
  80.     while (fgets(inline,MAXLINE,rcfile)) {
  81.         line++;
  82.     tok1 = strtok(inline," \t\r\n");
  83.     tok2 = strtok(NULL," \t\r\n");
  84.     tok3 = strtok(NULL," \t\r\n");
  85.     if (tok2 && !strcmp(tok2,"ICON") && (tok3 == (char *)NULL)) {
  86.             iconname[0] = '\0';
  87.         if (argc == 3) {
  88.                 strcpy(iconname,argv[2]);
  89.                 strcat(iconname,"\\");
  90.             }
  91.             strcat(iconname,tok1);
  92.             strcat(iconname,".ico");
  93.         fprintf(stdout,"%s\n",iconname);
  94.         geticon();
  95.     }
  96.     }
  97.     return (0);
  98. }
  99.